/*
 * @(#)OptionsTag.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */

package com.dcivision.framework.taglib.html;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.struts.util.ResponseUtils;

import com.dcivision.alert.bean.UpdateAlert;
import com.dcivision.dms.DmsOperationConstant;
import com.dcivision.dms.bean.DmsDocument;
import com.dcivision.dms.core.DocumentRetrievalManager;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.MessageResourcesFactory;
import com.dcivision.framework.OptionsListConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.Utility;
import com.dcivision.workflow.bean.WorkflowProgress;
import com.dcivision.workflow.bean.WorkflowStep;

/**
  OptionsTag.java

  <p>This class is to extend the OptionsTag provided by Apache Struts.<p>
  <p>Modification in "struts-html.tld"<br>
  <pre>
     [FROM]
     &lt;tagclass&gt;org.apache.struts.taglib.html.OptionsTag&lt;/tagclass&gt;
     [TO]
     &lt;tagclass&gt;com.dcivision.framework.taglib.html.OptionsTag&lt;/tagclass&gt;

     [ADDED]
     &lt;attribute&gt;
     &lt;name&gt;dbListName&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
     &lt;attribute&gt;
     &lt;name&gt;listName&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
     &lt;attribute&gt;
     &lt;name&gt;listArg1&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
     &lt;attribute&gt;
     &lt;name&gt;listArg2&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
     &lt;attribute&gt;
     &lt;name&gt;stringArray&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
     &lt;attribute&gt;
     &lt;name&gt;hasSelect&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
     &lt;attribute&gt;
     &lt;name&gt;convertLabel&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
     &lt;attribute&gt;
     &lt;name&gt;nowrap&lt;/name&gt;
     &lt;required&gt;false&lt;/required&gt;
     &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
     &lt;/attribute&gt;
 *
  </pre>
  </p>

  <p>USAGE:</p>
  <p>The following example shows that the options which retriving the table
     SETUP_OPTION_COUNTRY.</p>
  <p><code>&lt;html:options <strong>dbListName='countryList'</strong>/&gt;</code></p>
  <p>The following example shows that the options which retriving the predefined
     options of criteria list used in list search function.</p>
  <p><code>&lt;html:options <strong>listName='criteriaList'</strong>/&gt;</code></p>
  <p>All the list name are defined in <code>com.dcivision.framework.OptionsListConstant</code>

    @author          Wong Yam Lee
    @company         DCIVision Limited
    @creation date   08/07/2003
    @version         $Revision: 1.67.2.3 $
*/

public class OptionsTag extends com.dcivision.customize.CustomizedOptionsTag {

  public static final String REVISION = "$Revision: 1.67.2.3 $";


  /**
   * doStartTag
   *
   * Set the attributes 'name' and 'labelName',
   * according to dbListName or listName
   * If both are set, only dbListName is considered
   *
   * @return   SKIP_BODY
   */
  public int doStartTag() throws JspException {
    SessionContainer sessionContainer = (SessionContainer)this.pageContext.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
    SelectTag selectTag = (SelectTag) BodyTagSupport.findAncestorWithClass(this, SelectTag.class);

    if ("basicSearchField".equals(selectTag.getProperty())) {
      this.setHasSelect(false);
    }

    if ( sDbListName!=null ) {
      List lsName = new ArrayList();
      List lsLabelName = new ArrayList();
      PreparedStatement stat = null;
      ResultSet rs = null;
      Connection conn = (Connection)pageContext.getRequest().getAttribute(GlobalConstant.DB_KEY);

      if ( bHasSelect && selectTag.getMultiple()==null ) {
        lsName.add("");
        if (!Utility.isEmpty(sDisplayLabel)) {
          lsLabelName.add(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), sDisplayLabel));
        } else{
          lsLabelName.add(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one"));
        }
      }

      // get the ID and 2nd column from the table according to dbListName
      try {
        stat = conn.prepareStatement( getSqlStatement(sDbListName),ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
        rs = stat.executeQuery();
        while ( rs.next() ) {
          lsName.add( rs.getString(1) );
          lsLabelName.add( rs.getString(2) );
        }
      } catch (Exception e) {
        throw new JspException(e);
      } finally {
        try { stat.close(); } catch (Exception ignore) {} finally { stat = null; }
        try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
      }

      // set attribute 'name' and 'labelName'
      pageContext.setAttribute("name", lsName);
      pageContext.setAttribute("labelName", lsLabelName);
      super.setName("name");
      super.setLabelName("labelName");

    } else if ( sListName!=null ) {
      if (OptionsListConstant.LIST_CRITERIA.equals(sListName)) {
        this.setHasSelect(false);
      }

      String[] asName = null;
      String[] asLabelName = null;
      Object[] aoTempAry = null;

      // find the name and labelName according to sListName
      try {
        aoTempAry = getListData(sListName);
      } catch (Exception e) {
        throw new JspException(e);
      }

      asName = (String[])aoTempAry[0];
      asLabelName = (String[])aoTempAry[1];

      if ( bHasSelect && selectTag.getMultiple()==null ) {
        ArrayList alTmpName = new ArrayList();
        ArrayList alTmpLabelName = new ArrayList();

        alTmpName.add("");
        for (int i=0; i<asName.length; i++) {
          alTmpName.add(asName[i]);
        }
        asName = (String[])alTmpName.toArray(new String[0]);

        if (!Utility.isEmpty(sDisplayLabel)) {
          alTmpLabelName.add(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), sDisplayLabel));
        } else{
          alTmpLabelName.add(MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one"));
        }
        for (int i=0; i<asLabelName.length; i++) {
          alTmpLabelName.add(asLabelName[i]);
        }
        asLabelName = (String[])alTmpLabelName.toArray(new String[0]);
      }

      // set attribute 'name' and 'labelName'
      pageContext.setAttribute("name", asName);
      pageContext.setAttribute("labelName", asLabelName);
      super.setName("name");
      super.setLabelName("labelName");
    } else if ( saStringArray!= null ) {
      ArrayList alLabels = new ArrayList();
      ArrayList alValues = new ArrayList();
      String[] saLabels = null;
      String[] saValues = null;

      if (bHasSelect && selectTag.getMultiple()==null) {
        if (!Utility.isEmpty(sDisplayLabel)) {
          alLabels.add(sDisplayLabel);
        } else {
          alLabels.add("common.options.select_menu.select_one");
        }

        alValues.add("");
      }

      for (int i=0; i<saStringArray.length; i++) {
        if (saStringArray[i][0]!=null) {
          alLabels.add(saStringArray[i][0]);
        }
        alValues.add(saStringArray[i][1]);
      }

      saLabels = (String[])alLabels.toArray(new String[0]);
      saValues = (String[])alValues.toArray(new String[0]);

      pageContext.setAttribute("name", saValues);
      if (!Utility.isEmpty(alLabels)) {
        if (this.getConvertLabel()) {
          pageContext.setAttribute("labelName", this.getLabels(saLabels));
        } else {
          pageContext.setAttribute("labelName", saLabels);
        }
      } else {
        pageContext.setAttribute("labelName", saValues);
      }
      super.setName("name");
      super.setLabelName("labelName");
    } else if (Utility.isEmpty(saStringArray) && Utility.isEmpty(this.getLabelProperty())){
      //Add By Jim Zhou       2006/12/28      EIP-1284
      ArrayList alLabels = new ArrayList();
      ArrayList alValues = new ArrayList();
      String[] saLabels = null;
      String[] saValues = null;

      if (bHasSelect && selectTag.getMultiple()==null) {
        if (!Utility.isEmpty(sDisplayLabel)) {
          alLabels.add(sDisplayLabel);
        } else {
          alLabels.add("common.options.select_menu.select_one");
        }
        alValues.add("");
      }
      saLabels = (String[])alLabels.toArray(new String[0]);
      saValues = (String[])alValues.toArray(new String[0]);
      pageContext.setAttribute("name", saValues);
      if (!Utility.isEmpty(alLabels)) {
        if (this.getConvertLabel()) {
          pageContext.setAttribute("labelName", this.getLabels(saLabels));
        } else {
          pageContext.setAttribute("labelName", saLabels);
        }
      } else {
        pageContext.setAttribute("labelName", saValues);
      }
      super.setName("name");
      super.setLabelName("labelName");
      //Add End
    }

    return SKIP_BODY;
  }

  /**
   * doEndTag
   *
   * @return
   * @throws JspException
   */
  public int doEndTag() throws JspException {
    SelectTag selectTag = (SelectTag)BodyTagSupport.findAncestorWithClass(this, SelectTag.class);
    FormTag formTag = (FormTag)BodyTagSupport.findAncestorWithClass(this, FormTag.class);
    if (selectTag!=null && (selectTag.getTextOnly() || (formTag!=null&&formTag.getTextOnly()))) {
      Iterator valuesIterator = getIterator(name, property);
      Iterator labelsIterator = null;
      if ((labelName == null) && (labelProperty == null)) {
        labelsIterator = getIterator(name, property); // Same coll.
      } else {
        labelsIterator = getIterator(labelName, labelProperty);
      }

      selectTag.calculateMatchValues();

      // Render the options tags for each element of the values coll.
      while (valuesIterator.hasNext()) {
        Object valueObject = valuesIterator.next();
        if (valueObject == null) {
          valueObject = "";
        }
        String value = valueObject.toString();
        String label = value;
        if (labelsIterator.hasNext()) {
          Object labelObject = labelsIterator.next();
          if (labelObject == null) {
            labelObject = "";
          }
          label = labelObject.toString();
        }

        if (selectTag.isMatched(value)) {
          StringBuffer sbResult = new StringBuffer(ResponseUtils.filter(label));
          if (Utility.isEmpty(value)) {
            sbResult = new StringBuffer();
          }
          sbResult.append("<input type='hidden' name='");
          sbResult.append(selectTag.getProperty());
          sbResult.append("' value='");
          sbResult.append(ResponseUtils.filter(value.toString()));
          sbResult.append("'>");
          if ( !bNowrap ) {
            sbResult.append("<br>");
          }

          ResponseUtils.write(pageContext, sbResult.toString());
        }
      }
      return(EVAL_PAGE);
    } else {
      return(super.doEndTag());
    }
  }

  /**
   * release
   *
   * Release any acquired resources.
   */
  public void release() {
    super.release();
    saStringArray = null;
    sDbListName = null;
    sListName = null;
    sListArg1 = null;
    sListArg2 = null;
    bHasSelect = true;
    bNowrap = false;
  }

  /**
   * getSqlStatement
   *
   * Prepare SQL string according to sListName
   * Available list to table mapping:
   * countryList    -- SETUP_OPTION_COUNTRY
   * salutationList -- SETUP_OPTION_SALUTATION
   *
   * @param  sListName     The list name of the table
   * @return SQL string
   */
  protected String getSqlStatement(String sDbListName) throws Exception {
    StringBuffer sqlStat = new StringBuffer();

    // select query to table according to sListName
    if ( OptionsListConstant.DBLIST_COUNTRY.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, COUNTRY_NAME, DISPLAY_SEQ ");
      sqlStat.append("FROM      SETUP_OPTION_COUNTRY ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND STATUS = 'A' ");
      sqlStat.append("ORDER BY  DISPLAY_SEQ ASC, COUNTRY_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_SALUTATION.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, SALUTATION_NAME, DISPLAY_SEQ ");
      sqlStat.append("FROM      SETUP_OPTION_SALUTATION ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A'  AND STATUS = 'A' ");
      sqlStat.append("ORDER BY  DISPLAY_SEQ ASC, SALUTATION_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_FORM_CATEGORY.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, FORM_CATEGORY_NAME ");
      sqlStat.append("FROM      SETUP_OPTION_FORM_CATEGORY ");
      sqlStat.append("WHERE     RECORD_STATUS='A' ");
      sqlStat.append("ORDER BY  FORM_CATEGORY_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_USER_RECORD.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, FULL_NAME ");
      sqlStat.append("FROM      USER_RECORD ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND STATUS = 'A' ");
      sqlStat.append("ORDER BY  FULL_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_CONTACT_CATEGORY.equals(sDbListName) ) {
        sqlStat.append("SELECT    ID,CONTACT_CATEGORY, DISPLAY_SEQ ");
        sqlStat.append("FROM      SETUP_OPTION_CONTACT_CATEGORY ");
        sqlStat.append("WHERE     RECORD_STATUS = 'A' AND STATUS = 'A' ");
        sqlStat.append("ORDER BY  DISPLAY_SEQ ASC, CONTACT_CATEGORY ASC ");

    } else if ( OptionsListConstant.DBLIST_USER_PRIVATE_GROUP.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, GROUP_NAME ");
      sqlStat.append("FROM      USER_GROUP ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND GROUP_TYPE = 'V' AND OWNER_USER_RECORD_ID = " + this.getListArg1() + " ");
      sqlStat.append("ORDER BY  GROUP_NAME ASC");

    } else if ( OptionsListConstant.DBLIST_USER_PUBLIC_GROUP.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, GROUP_NAME ");
      sqlStat.append("FROM      USER_GROUP ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND GROUP_TYPE = 'P' ");
      sqlStat.append("ORDER BY  GROUP_NAME ASC");

    } else if ( OptionsListConstant.DBLIST_USER_ROLE.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, ROLE_NAME ");
      sqlStat.append("FROM      USER_ROLE ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' ");
      sqlStat.append("ORDER BY  ROLE_NAME ASC");

    } else if ( OptionsListConstant.DBLIST_STAFF_RECORD.equals(sDbListName) ) {
        sqlStat.append("SELECT    ID, FULL_NAME ");
        sqlStat.append("FROM      STAFF_RECORD ");
        sqlStat.append("WHERE     RECORD_STATUS = 'A' ");
        sqlStat.append("ORDER BY  FULL_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_WORKFLOW_GROUP.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, GROUP_NAME ");
      sqlStat.append("FROM      WORKFLOW_GROUP ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' ");
      sqlStat.append("AND       ID IN ("+this.getListArg1()+") ");
      sqlStat.append("ORDER BY  GROUP_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_WORKFLOW_CATEGORY.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, WORKFLOW_CATEGORY_NAME, DISPLAY_SEQ ");
      sqlStat.append("FROM      SETUP_OPTION_WORKFLOW_CATEGORY ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND STATUS = 'A' ");
      sqlStat.append("ORDER BY  DISPLAY_SEQ ASC, WORKFLOW_CATEGORY_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_WORKFLOW_STEP.equals(sDbListName) ) {
      String[] colsName = {"STEP_SEQ", "STEP_NAME"};
      //sqlStat.append("SELECT    ID, "+DataSourceFactory.formatSQLConcatStatement(colsName, ". ") + " STEP_DISPLAY_NAME ");
      //TC.DELETE : if use concatStatement when the column contains chinese character will course issue,
      sqlStat.append("SELECT ID, STEP_NAME  ");
      sqlStat.append("FROM      WORKFLOW_STEP ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND STEP_SEQ <> "+WorkflowStep.START_STEP_SEQ_NO+" AND STEP_SEQ <> "+WorkflowStep.END_STEP_SEQ_NO+" AND WORKFLOW_RECORD_ID = " + this.getListArg1() + " ");
      if ( !Utility.isEmpty(this.getListArg2()) ) {
        sqlStat.append("AND ID <> " + this.getListArg2() + " ");
      }
      if (!Utility.isEmpty(this.getListArg3())){
          sqlStat.append("AND ID <> " + this.getListArg3() + " ");
        }

      sqlStat.append("ORDER BY  STEP_NAME ASC ");

    } else if ( OptionsListConstant.DBLIST_STAFF_HIERARCHY.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, NAME ");
      sqlStat.append("FROM      STAFF_HIERARCHY ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND PARENT_ID = " + this.getListArg1() + " ");
      sqlStat.append("ORDER BY  NAME ASC");

    } else if ( OptionsListConstant.DBLIST_DMS_USER_DEFINED_INDEX.equals(sDbListName) ) {
      sqlStat.append("SELECT    ID, USER_DEFINED_TYPE ");
      sqlStat.append("FROM      SYS_USER_DEFINED_INDEX ");
      sqlStat.append("WHERE     OBJECT_TYPE = '"+GlobalConstant.OBJECT_TYPE_DOCUMENT+"' AND RECORD_STATUS = 'A' ");
      sqlStat.append("ORDER BY  USER_DEFINED_TYPE ASC ");

    } else if ( OptionsListConstant.DBLIST_ALL_ACCESSABLE_ROOT_LIST.equals(sDbListName) ) {
      SessionContainer sessionContainer = (SessionContainer)this.pageContext.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
      Connection conn = (Connection)pageContext.getRequest().getAttribute(GlobalConstant.DB_KEY);
      //Public Root
      List listID = sessionContainer.getPermissionManager().getAccessibleObjectIDList(GlobalConstant.OBJECT_TYPE_DOCUMENT, new Integer(0));
      //Personal Root
      DocumentRetrievalManager docRetrevalManager = new DocumentRetrievalManager(sessionContainer, conn);
      DmsDocument personalRoot = docRetrevalManager.getDocumentByNameParentIDCreatorID(DmsOperationConstant.DMS_PERSONAL_ROOT, new Integer(0), sessionContainer.getUserRecordID());
      listID.add(personalRoot.getID());
      sqlStat.append("SELECT    ROOT_ID, DOCUMENT_NAME ");
      sqlStat.append("FROM      DMS_DOCUMENT ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A' AND ( ");
      for (int i=0; i<listID.size(); i++){
        if (i!=0) sqlStat.append(" OR ");
        sqlStat.append(" ID = "+listID.get(i));
      }
      sqlStat.append(") ORDER BY  DOCUMENT_NAME ASC ");

    } else if (OptionsListConstant.DBLIST_DOCUMENT_RELATIONSHIP.equals(sDbListName)) {
      sqlStat.append("SELECT    RELATIONSHIP_CODE, RELATIONSHIP_NAME ");
      sqlStat.append("FROM      SETUP_OPTION_DOC_RELATIONSHIP ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A'  AND STATUS = 'A' ");
      sqlStat.append("ORDER BY  DISPLAY_SEQ ASC, RELATIONSHIP_NAME ASC ");

    } else if (OptionsListConstant.DBLIST_DOCUMENT_NON_SHORTCUT_RELATIONSHIP.equals(sDbListName)) {
      sqlStat.append("SELECT    RELATIONSHIP_CODE, RELATIONSHIP_NAME ");
      sqlStat.append("FROM      SETUP_OPTION_DOC_RELATIONSHIP ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A'  AND STATUS = 'A' ");
      sqlStat.append("AND       RELATIONSHIP_CODE<> 'L' ");
      sqlStat.append("ORDER BY  DISPLAY_SEQ ASC, RELATIONSHIP_NAME ASC ");

    } else if (OptionsListConstant.DBLIST_LOC_MASTER.equals(sDbListName)) {
      sqlStat.append("SELECT    ID,LOC_PATH ");
      sqlStat.append("FROM      DMS_LOC_MASTER ");
      sqlStat.append("WHERE     RECORD_STATUS = 'A'");
      sqlStat.append("ORDER BY  LOC_PATH ASC ");
    } else {
      return super.getSqlStatement(sDbListName);
    }
    return sqlStat.toString();
  }

  /**
   * getListData
   *
   * Get name and labelName of the list
   * Available list: criteriaList
   *
   * @param  sListName
   * @return Object array storing array of name and array of labelName
   */
  protected Object[] getListData(String sListName) throws Exception {
    String[] asName;
    String[] asLabelName;

    if ( OptionsListConstant.LIST_CRITERIA.equals(sListName) ) {
      // *** Use "LIKE " to distinguish "LIKE" for searching criteria. "LIKE" will
      // *** translate to "%KEYWORD%" while "LIKE " will translate to "KEYWORD%".
      asName = new String[] { "LIKE", "LIKE ", "=", "<>", ">=", ">", "<", "<=" };
      asLabelName = new String[] { "common.options.criteria.contains",
                                   "common.options.criteria.starts_with",
                                   "common.options.criteria.equals",
                                   "common.options.criteria.not_equals",
                                   "common.options.criteria.greater_than_or_equals",
                                   "common.options.criteria.greater_than",
                                   "common.options.criteria.less_than",
                                   "common.options.criteria.less_than_or_equals"
                                 };
    } else if ( OptionsListConstant.LIST_STATUS_TYPE.equals(sListName) ) {
      asName = new String[] {GlobalConstant.STATUS_ACTIVE, GlobalConstant.STATUS_INACTIVE};
      asLabelName = new String[] { "common.options.status_A",
                                   "common.options.status_I"
                                 };
    } else if ( OptionsListConstant.LIST_RELEASE_STATUS.equals(sListName) ) {
      asName = new String[] {GlobalConstant.RECORD_PENDING, GlobalConstant.RECORD_RELEASED};
      asLabelName = new String[] { "common.options.status_P",
                                   "common.options.status_R"
                                  };
    } else if ( OptionsListConstant.LIST_WORKFLOW_PRIORITY.equals(sListName) ) {
      asName = new String[] {GlobalConstant.PRIORITY_HIGH, GlobalConstant.PRIORITY_MEDIUM, GlobalConstant.PRIORITY_LOW};
      asLabelName = new String[] { "workflow.label.priority_3",
                                   "workflow.label.priority_2",
                                   "workflow.label.priority_1"
                                  };
    } else if ( OptionsListConstant.LIST_WORKFLOW_PROGRESS_STATUS.equals(sListName) ) {
      asName = new String[] { WorkflowProgress.STATUS_SUBMIT,
                              WorkflowProgress.STATUS_APPROVE,
                              WorkflowProgress.STATUS_REJECT,
                              WorkflowProgress.STATUS_YES,
                              WorkflowProgress.STATUS_NO,
                              WorkflowProgress.STATUS_PENDING,
                              WorkflowProgress.STATUS_GENERAL_ACCOMPLISHMENT,
                              WorkflowProgress.STATUS_NO_RESPONSE
                            };
      asLabelName = new String[] { "workflow.label.step_status_S",
                                   "workflow.label.step_status_A",
                                   "workflow.label.step_status_R",
                                   "workflow.label.step_status_T",
                                   "workflow.label.step_status_F",
                                   "workflow.label.step_status_P",
                                   "workflow.label.step_status_G",
                                   "workflow.label.step_status_N"
                                 };
    } else if ( OptionsListConstant.LIST_TO_DO_TASK_NO_RESPONSE_ACTION.equals(sListName) ) {
      asName = new String[] { WorkflowStep.NO_RESPONSE_ACTION_KEEP,
                              WorkflowStep.NO_RESPONSE_ACTION_COMPLETE,
                              WorkflowStep.NO_RESPONSE_ACTION_STOP,
                              WorkflowStep.NO_RESPONSE_ACTION_ROUTE
                            };
      asLabelName = new String[] { "workflow.label.action_after_due_K",
                                   "workflow.label.action_after_due_C",
                                   "workflow.label.action_after_due_S",
                                   "workflow.label.action_after_due_O"
                                 };
    } else if ( OptionsListConstant.LIST_APPROVAL_TASK_NO_RESPONSE_ACTION.equals(sListName) ) {
      asName = new String[] { WorkflowStep.NO_RESPONSE_ACTION_KEEP,
                              WorkflowStep.NO_RESPONSE_ACTION_APPROVE,
                              WorkflowStep.NO_RESPONSE_ACTION_REJECT,
                              WorkflowStep.NO_RESPONSE_ACTION_STOP,
                              WorkflowStep.NO_RESPONSE_ACTION_ROUTE
                            };
      asLabelName = new String[] { "workflow.label.action_after_due_K",
                                   "workflow.label.action_after_due_A",
                                   "workflow.label.action_after_due_R",
                                   "workflow.label.action_after_due_S",
                                   "workflow.label.action_after_due_O"
                                 };
    } else if (OptionsListConstant.LIST_REMINDER_AMOUNT.equals(sListName)) {

      asName = new String[] {"0;"+UpdateAlert.MINUTE, "15;"+UpdateAlert.MINUTE, "30;"+UpdateAlert.MINUTE, "45;"+UpdateAlert.MINUTE,
                             "1;"+UpdateAlert.HOUR, "2;"+UpdateAlert.HOUR, "3;"+UpdateAlert.HOUR, "4;"+UpdateAlert.HOUR, "5;"+UpdateAlert.HOUR, "6;"+UpdateAlert.HOUR, //"7;"+UpdateAlert.HOUR ,"8;"+UpdateAlert.HOUR ,"9;"+UpdateAlert.HOUR ,"10;"+UpdateAlert.HOUR,
                             "1;"+UpdateAlert.DAY, "2;"+UpdateAlert.DAY, "3;"+UpdateAlert.DAY, "4;"+UpdateAlert.DAY, "5;"+UpdateAlert.DAY, "6;"+UpdateAlert.DAY, //"7;"+UpdateAlert.DAY, "8;"+UpdateAlert.DAY, "9;"+UpdateAlert.DAY, "10;"+UpdateAlert.DAY,
                             "1;"+UpdateAlert.WEEK, "2;"+UpdateAlert.WEEK, "3;"+UpdateAlert.WEEK, "4;"+UpdateAlert.WEEK, "5;"+UpdateAlert.WEEK, "6;"+UpdateAlert.WEEK,
                             "1;"+UpdateAlert.MONTH, "2;"+UpdateAlert.MONTH, "3;"+UpdateAlert.MONTH, "4;"+UpdateAlert.MONTH, "5;"+UpdateAlert.MONTH, "6;"+UpdateAlert.MONTH,
                             "1;"+UpdateAlert.YEAR, "2;"+UpdateAlert.YEAR//, "3;"+UpdateAlert.YEAR, "4;"+UpdateAlert.YEAR, //"5;"+UpdateAlert.YEAR, "6;"+UpdateAlert.YEAR
                            };
      asLabelName = new String[] {"alert.label.reminder_amount_0_B", "alert.label.reminder_amount_15_B", "alert.label.reminder_amount_30_B", "alert.label.reminder_amount_45_B",
                                  "alert.label.reminder_amount_1_C", "alert.label.reminder_amount_2_C", "alert.label.reminder_amount_3_C", "alert.label.reminder_amount_4_C", "alert.label.reminder_amount_5_C", "alert.label.reminder_amount_6_C",
                                  "alert.label.reminder_amount_1_D", "alert.label.reminder_amount_2_D", "alert.label.reminder_amount_3_D", "alert.label.reminder_amount_4_D", "alert.label.reminder_amount_5_D", "alert.label.reminder_amount_6_D",
                                  "alert.label.reminder_amount_1_E", "alert.label.reminder_amount_2_E", "alert.label.reminder_amount_3_E", "alert.label.reminder_amount_4_E", "alert.label.reminder_amount_5_E", "alert.label.reminder_amount_6_E",
                                  "alert.label.reminder_amount_1_F", "alert.label.reminder_amount_2_F", "alert.label.reminder_amount_3_F", "alert.label.reminder_amount_4_F", "alert.label.reminder_amount_5_F", "alert.label.reminder_amount_6_F",
                                  "alert.label.reminder_amount_1_G", "alert.label.reminder_amount_2_G"//, "alert.label.reminder_amount_3_G", "alert.label.reminder_amount_4_G"
                                 };
    } else {
      return super.getListData(sListName);
    }

    return new Object[] { asName, this.getLabels(asLabelName) };
  }

}
